<?php

/*
 * Created by generator
 *
 */

/**
 * Recupere la liste des enregistrements
 * @param object $db database object
 * @return array of data
 */
if (!function_exists('getAllactivitesFromDB')) {
	function getAllactivitesFromDB($db) {
		$sql = "SELECT actidact, actlblib, actidniv, actidtra, actidsai, actidpro, actlbjou, actlbhdb, actlbdfn, actfgmai, actidsit, actmocot from gyaact ";
		$query = $db->query($sql);

		// recuperer les enregistrements
		$records = array();
		foreach ($query->result_array() as $row) {
			$records[] = $row;
		}
		return $records;
	}
}


/**
 * Insere un nouvel enregistrement
 * @param object $db database object
 * @param string ...
 * @return number identifiant
 */
if (!function_exists('insertNewactivite')) {
	function insertNewactivite($db, $actlblib, $actidniv, $actidtra, $actidsai, $actidpro, $actlbjou, $actlbhdb, $actlbdfn, $actfgmai, $actidsit, $actmocot) {
		$data=array( 'actlblib'=>$actlblib, 'actidniv'=>$actidniv, 'actidtra'=>$actidtra, 'actidsai'=>$actidsai, 'actidpro'=>$actidpro, 'actlbjou'=>$actlbjou, 'actlbhdb'=>$actlbhdb, 'actlbdfn'=>$actlbdfn, 'actfgmai'=>$actfgmai, 'actidsit'=>$actidsit, 'actmocot'=>$actmocot );
		$db->insert('gyaact',$data);
		return $db->insert_id();
	}
}

/**
 * Mise a jour d'un enregistrement
 */
if (!function_exists('updateactivite')) {
	function updateactivite($db, $actidact, $actlblib, $actidniv, $actidtra, $actidsai, $actidpro, $actlbjou, $actlbhdb, $actlbdfn, $actfgmai, $actidsit, $actmocot) {
		$sql = "update gyaact set actlblib = ?, actidniv = ?, actidtra = ?, actidsai = ?, actidpro = ?, actlbjou = ?, actlbhdb = ?, actlbdfn = ?, actfgmai = ?, actidsit = ?, actmocot = ? where actidact=?";
		$query = $db->query($sql, array($actlblib, $actidniv, $actidtra, $actidsai, $actidpro, $actlbjou, $actlbhdb, $actlbdfn, $actfgmai, $actidsit, $actmocot, (int)$actidact ));
	}
}


/**
 * Suppression d'un enregistrement
 */
if (!function_exists('deleteactivite')) {
	function deleteactivite($db, $actidact) {
		$sql = "delete from gyaact where actidact=?";
		$query = $db->query($sql, array((int)$actidact));
	}
}


/**
 * Recupere les informations d'un enregistrement
 * @param object $db database object
 * @param int id de l'enregistrement
 * @return array
 */
if (!function_exists('getactiviteRow')) {
	function getactiviteRow($db, $actidact) {
		$sql = "select actidact, actlblib, actidniv, actidtra, actidsai, actidpro, actlbjou, actlbhdb, actlbdfn, actfgmai, actidsit, actmocot from gyaact " .
		"where actidact=?";
		$query = $db->query($sql, array((int)$actidact));
		if ($query->num_rows() == 0) {
			return null;
		}
		return $query->row_array();
	}
}

	/***************************************************************************
	 * USER DEFINED FUNCTIONS
	 ***************************************************************************/

if (!function_exists('getAllactivitesFromDBForAdherentForSaison')) {
	function getAllactivitesFromDBForAdherentForSaison($db, $adhidadh, $saiidsai) {
		$sql = "select actidact, actlblib, actidniv, actidtra, actidsai, actidpro, actlbjou, actlbhdb, actlbdfn, actfgmai, actidsit, actmocot ".
		" from gyaact LEFT JOIN gyaxaa xaa on (gyaact.actidact = xaa.xaaidact)" .
		" where xaaidadh = ? and actidsai = ?";
		$query = $db->query($sql, array((int)$adhidadh, (int)$saiidsai));
		
		// recuperer les enregistrements
		$records = array();
		foreach ($query->result_array() as $row) {
			$records[] = $row;
		}
		return $records;
	}
}


if (!function_exists('getAllactivitesFromDBForSaison')) {
	function getAllactivitesFromDBForSaison($db, $saiidsai, $orderBy = "") {
		$sql = "select actidact, actlblib, actidniv, actidtra, actidsai, actidpro, actlbjou, actlbhdb, actlbdfn, actfgmai, actidsit, actmocot from gyaact" .
		" where actidsai = ?";
		if( $orderBy != "") {
			$sql .= " order by ". $orderBy;
		}
		$query = $db->query($sql, array((int)$saiidsai));
		
		// recuperer les enregistrements
		$records = array();
		foreach ($query->result_array() as $row) {
			$records[] = $row;
		}
		return $records;
	}
}



if (!function_exists('getAllactivitesFromDBHaving')) {
	function getAllactivitesFromDBHaving($db, $actidsai, $actlblib, $actidniv, 
			$actidtra, $actidpro, $actlbjou, $actlbhdb,
			$actlbdfn, $actidsit, $orderBy = "") {
		
		$parameters = array((int)$actidsai);
		$sql = "select actidact, actlblib, actidniv, actidtra, actidsai, actidpro, actlbjou, actlbhdb, actlbdfn, actfgmai, actidsit, actmocot from gyaact" .
		" where actidsai = ?"; // saison obligatoire
		
		if( $actlblib != null ) {
			$sql .= " and actlblib like ?";
			$parameters[] = $actlblib;
		}
		if( $actidniv != null ) {
			$sql .= " and actidniv = ?";
			$parameters[] = $actidniv;
		}
		if( $actidtra != null ) {
			$sql .= " and actidtra = ?";
			$parameters[] = $actidtra;
		}
		if( $actidpro != null ) {
			$sql .= " and actidpro = ?";
			$parameters[] = $actidpro;
		}
		if( $actlbjou != null ) {
			$sql .= " and actlbjou = ?";
			$parameters[] = $actlbjou;
		}
		if( $actlbhdb != null ) {
			$sql .= " and actlbhdb = ?";
			$parameters[] = $actlbhdb;
		}
		if( $actlbdfn != null ) {
			$sql .= " and actlbdfn = ?";
			$parameters[] = $actlbdfn;
		}
		if( $actidsit != null ) {
			$sql .= " and actidsit = ?";
			$parameters[] = $actidsit;
		}
		
		if( $orderBy != "") {
			$sql .= " order by ". $orderBy;
		}
		$query = $db->query($sql, $parameters);
		
		// recuperer les enregistrements
		$records = array();
		foreach ($query->result_array() as $row) {
			$records[] = $row;
		}
		return $records;
	}
}


?>
